/*
 *  testxmldom.cpp
 *
 *  Created by Garrett williams on 5/19/05.
 *  Copyright 2005 Drag'N Flies. All rights reserved.
 *
 */

#include "ssdom.h"
#include <iostream>

using namespace std;

int main (int argc, char* argv[])
{
    if(2 > argc)
    {
        cout << "< In file > < out file > \n";
    }
    else
    try{
        SSDOM xml(argv[1]); // read the xml file
        xml.write(argv[2]); // write the xml tree
        SSLeaf *leaf;
        SSLeafStack stack;
        leaf = xml.searchNext(xml.getHead(),"head",true);
        xml.listNext(stack,leaf,"set",true);
        stack.clear();
        leaf = xml.searchNext(xml.getHead(),"level"); // find a leaf in the tree
        xml.listNext(stack,leaf,"data",true); // create a stack of leaves with tag of 'set'
        while(stack.pop(leaf)) // go through the stack of leaves
        {
            const char *data; // print out the data retreved.
            //leaf = xml.searchNext(leaf,"data"); // get some data from the leaf tree.
            if(leaf)
            {
                data = leaf->getTag();
                cout << data << " " ;
                data = leaf->getValue();
                if(data) // if null is passed to cout an error will occur.
                    cout << data;
                cout << endl;
            }
        }
        stack.clear();
        leaf = xml.searchNext(xml.getHead(),"head",true);
        xml.listNext(stack,leaf,"set",true);
        while(stack.pop(leaf)) // go through the stack of leaves
        {
            const char *data; // print out the data retreved.
            if(leaf)
            {
                data = leaf->getTag();
                cout << data << " " ;
                data = leaf->getValue();
                if(data) // if null is passed to cout an error will occur.
                    cout << data;
                cout << endl;
            }
        }
    }catch(const char* r){
        cout << r << endl;
        cout << "Proublem with xml\n";
    }
    cout << "Finished\n";
    return 0;
}
